package com.android.gtravelling;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class AddActivity extends Activity {

	private DBAdapter mDB;

	@Override
	public void onCreate(Bundle ds) {
		super.onCreate(ds);
		setContentView(R.layout.new_edit_contact);

		mDB = new DBAdapter(this);
		mDB.open();
		
		
		Button btnSave = (Button) findViewById(R.id.bsave);
		OnClickListener listen = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (btnAddClick() == -1) {
					displayAMessage("Insert Unsuccessful");
				} else {
					displayAMessage("Insert Successful");
				}
				Intent is = new Intent(v.getContext(), GTravellingActivity.class);
				startActivity(is);

			}
		};
		btnSave.setOnClickListener(listen);
		

	}

	public void displayAMessage(String msg) {

		AlertDialog alertDialog;
		alertDialog = new AlertDialog.Builder(this).create();
		alertDialog.setTitle("Message");
		alertDialog.setMessage(msg);

		alertDialog.show();
	}

	public long btnAddClick() {

		TextView txtName = (TextView) findViewById(R.id.cname_edit);
		TextView txtPhone = (TextView) findViewById(R.id.cphone_edit);
		TextView txtEmail = (TextView) findViewById(R.id.cemail_edit);

		return mDB.createUser(txtName.getText().toString(), txtPhone.getText()
				.toString(),txtEmail.getText().toString());
	}

}
